package yawning.mew.cat;

import yawning.mew.cat.CatModelSimState.CatTargetData;
import yawning.mew.sim.SimulationAction;

public class SkullBashAction implements SimulationAction {
	CatModelSimState mState;
	private CatTargetData mTargetData;
	private String mTargetName;

	SkullBashAction(CatModelSimState state, CatTargetData targetData) {
		mState = state;
		mTargetData = targetData;
		mTargetName = mTargetData.getSimulationTarget().getTarget().getName();
	}

	public double perform() {
		int cost = mState.getEnergyCost(mState.mModel.skullBashCost);
		if (mState.getEnergy() < cost) return SimulationAction.ACTION_FAIL;
		int prevEnergy = mState.getEnergy();

		mState.mSkullBashCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.skullBashCDDuration;

		if (mState.mIsLogging) mState.mLog.log("Skull Bash: %s\n", mTargetName);

		// Per 4.1 PTR patch notes, all interrupts are reliable.
		mNrSkullBashHit++;
		mTargetData.getSimulationTarget().getTargetCastEv().interrupt();

		mState.onEnergyConsumer(cost);

		mState.logEnergyChange(prevEnergy);

		return 0.0f;
	}

	int mNrSkullBashHit = 0;
	int mNrSkullBashMiss = 0;
}
